#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main (int argc, char const* argv[])
{

    int cnt, n;
    int d, m, y;
    char buf[16];

    scanf("%d", &n);
    printf("%d\n", n);
    while (n--) {

    scanf("%d", &d);
    scanf("%s", buf);
    scanf("%s", buf);
    scanf("%d", &y);

    if (!strcmp(buf, "pop")) {
        m = 0;
    } else if (!strcmp(buf, "no")) {
        m = 1;
    } else if (!strcmp(buf, "zip")) {
        m = 2;
    } else if (!strcmp(buf, "zotz")) {
        m = 3;
    } else if (!strcmp(buf, "tzec")) {
        m = 4;
    } else if (!strcmp(buf, "xul")) {
        m = 5;
    } else if (!strcmp(buf, "yoxkin")) {
        m = 6;
    } else if (!strcmp(buf, "mol")) {
        m = 7;
    } else if (!strcmp(buf, "chen")) {
        m = 8;
    } else if (!strcmp(buf, "yax")) {
        m = 9;
    } else if (!strcmp(buf, "zac")) {
        m = 10;
    } else if (!strcmp(buf, "ceh")) {
        m = 11;
    } else if (!strcmp(buf, "mac")) {
        m = 12;
    } else if (!strcmp(buf, "kankin")) {
        m = 13;
    } else if (!strcmp(buf, "muan")) {
        m = 14;
    } else if (!strcmp(buf, "pax")) {
        m = 15;
    } else if (!strcmp(buf, "koyab")) {
        m = 16;
    } else if (!strcmp(buf, "cumhu")) {
        m = 17;
    } else if (!strcmp(buf, "uayet")) {
        m = 18;
    }
    cnt = y * 365 + m * 20 + d;

    y = cnt / 260;
    m = cnt % 20;
    d = cnt % 13;

    switch (m) {
        case 0:
            strcpy(buf, "imix");
            break;
        case 1:
            strcpy(buf, "ik");
            break;
        case 2:
            strcpy(buf, "akbal");
            break;
        case 3:
            strcpy(buf, "kan");
            break;
        case 4:
            strcpy(buf, "chicchan");
            break;
        case 5:
            strcpy(buf, "cimi");
            break;
        case 6:
            strcpy(buf, "manik");
            break;
        case 7:
            strcpy(buf, "lamat");
            break;
        case 8:
            strcpy(buf, "muluk");
            break;
        case 9:
            strcpy(buf, "ok");
            break;
        case 10:
            strcpy(buf, "chuen");
            break;
        case 11:
            strcpy(buf, "eb");
            break;
        case 12:
            strcpy(buf, "ben");
            break;
        case 13:
            strcpy(buf, "ix");
            break;
        case 14:
            strcpy(buf, "mem");
            break;
        case 15:
            strcpy(buf, "cib");
            break;
        case 16:
            strcpy(buf, "caban");
            break;
        case 17:
            strcpy(buf, "eznab");
            break;
        case 18:
            strcpy(buf, "canac");
            break;
        case 19:
            strcpy(buf, "ahau");
            break;
    }

    printf("%d %s %d\n", d+1, buf, y);
    }

    return 0;
}
